import request from '@api/request';
import { HttpUrl } from '@api/httpUrl';
import { useUserStore } from '@/store/modules/user';

// 获取生产管控 区分标识 -- purchaseModel字段中的productionControl(Boolean)
export function getProductionControlList(available: string[], currentPage: number, pageSize: number) {
    return request.get<AjaxResponse['purchaseList']>(HttpUrl.getProductionControlList, { params: { available, currentPage, pageSize } });
}

// 获取生产列表
export function getProductionList(productionType: string, productionStatus: string[], page: number, pageSize: number) {
    return request.get<AjaxResponse['productionList']>(HttpUrl.getProductionList, { params: { productionType, productionStatus, page, pageSize } });
}

// 获取生产日志
export function getProductionLogList(productId: string) {
    return request.get<AjaxResponse['productionList'][]>(HttpUrl.getProductionLogList, { params: { productId } });
}

// 创建生产管控
export function createProductionControl(productionControlForm: AjaxRequest['productionControlForm']) {
    return request.post(HttpUrl.createProductionControl, { ...productionControlForm });
}
// 撤回生产管控
export function revokeProductionControl(purchaseId: string) {
    return request.post(HttpUrl.revokeProductionControl, { purchaseId });
}

// 更新生产管控
export function updateProduction(productionId: string, field: string, value: string | number) {
    return request.put(HttpUrl.updateProduction, { productionId, field, value });
}

// 下放生产管控
export function dispatchProductionControl(
    productionId: string,
    purchaseId: string,
    productionType: string,
    productionNumber: number,
    productionRemark: string,
    userId: string = useUserStore().id || '未知'
) {
    return request.post(HttpUrl.dispatchProductionControl, { productionId, purchaseId, productionType, productionNumber, productionRemark, userId });
}

// 入库
export function warehouseIn(
    productionId: string,
    purchaseId: string,
    productionNumber: number,
    productionRemark: string,
    customerId: string,
    productId: string,
    username: string = useUserStore().username || '未知',
    userId: string = useUserStore().id || '未知'
) {
    return request.post(HttpUrl.warehouseIn, {
        productionId,
        purchaseId,
        productionNumber,
        productionRemark,
        customerId,
        productId,
        username,
        userId,
    });
}

// 重置生产管控
export function resetProductionControl(productionId: string) {
    return request.put(HttpUrl.resetProductionControl, { productionId });
}
